package club.gskj.gulimall.member.web;

import club.gskj.common.utils.R;
import club.gskj.gulimall.member.feign.OrderFeignService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
public class MermberWebController {

    @Autowired
    private OrderFeignService orderFeignService;

    /***
     *  跳转到会员订单列表
     * @return
     */
    @GetMapping("/memberOrder.html")
    public String memberOrder(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, Model model, HttpServletRequest request) {
        // 获取支付宝返回来的参数
        Map<String, Object> params = new HashMap<>(5);
        // 页码
        params.put("page", pageNum.toString());

        R r = orderFeignService.listOrderWithItems(params);
        model.addAttribute("order", r);
        log.info("r : {}", JSON.toJSONString(r));
        // 查询当前登陆的用户
        return "orderList";
    }

}
